import 'package:flutter/material.dart';
import 'package:xrenovation/views/auth/login_page.dart';
import 'package:xrenovation/views/auth/register_page.dart';
import 'package:xrenovation/views/auth/reset_page.dart';
import 'package:xrenovation/views/chat/chat_page.dart';
import 'package:xrenovation/views/contractors/contractors_page.dart';
import 'package:xrenovation/views/home/home_page.dart';
import 'package:xrenovation/views/policy/privacy_policy_page.dart';
import 'package:xrenovation/views/policy/terms_service_page.dart';
import 'package:xrenovation/views/projects/projects_page.dart';
import 'package:xrenovation/views/projects/tasks_page.dart';
import 'package:xrenovation/views/subscription/subscription_page.dart';

class AppRoutes {
  static const String login = '/login';
  static const String register = '/register';
  static const String reset = '/reset';
  static const String home = '/home';
  static const String projects = '/projects';
  static const String tasks = '/tasks';
  static const String contractors = '/contractors';
  static const String chat = '/chat';
  static const String privacyPolicy = '/privacyPolicy';
  static const String termsService = '/termsService';
  static const String subscription = '/subscription';

  // 添加所有有效路由的列表
  static const List<String> routes = [
    login,
    register,
    reset,
    home,
    projects,
    tasks,
    contractors,
    chat,
    privacyPolicy,
    termsService,
    subscription,
  ];

  static Route<dynamic> generateRoute(RouteSettings settings) {
    debugPrint('Routing to: ${settings.name}');
    switch (settings.name) {
      case login:
        return MaterialPageRoute(builder: (_) => const LoginPage());
      case register:
        return MaterialPageRoute(builder: (_) => const RegisterPage());
      case reset:
        return MaterialPageRoute(builder: (_) => const ResetPage());
      case projects:
        return MaterialPageRoute(builder: (_) => const ProjectsPage());
      case tasks:
        final args = settings.arguments as Map<String, dynamic>;
        return MaterialPageRoute(
          builder: (_) => TasksPage(projectId: args['projectId']),
        );
      case chat:
        return MaterialPageRoute(builder: (_) => const ChatPage());
      case contractors:
        return MaterialPageRoute(builder: (_) => const ContractorsPage());
      case privacyPolicy:
        return MaterialPageRoute(builder: (_) => const PrivacyPolicyPage());
      case termsService:
        return MaterialPageRoute(builder: (_) => const TermsServicePage());
      case subscription:
        return MaterialPageRoute(builder: (_) => const SubscriptionPage());
      default:
        // 所有未知路由重定向到home
        return MaterialPageRoute(builder: (_) => const HomePage());
    }
  }
}
